<?php


namespace App\Http\Controllers\Admin;
use App\Http\Controllers\BaseController;
use App\Models\Config;
use Dingo\Api\Http\Request;

class ConfigController extends BaseController
{

    public function info(Request $request) {
        $info = Config::where('category', 'setting')->pluck( 'value', 'key');
        return $this->success($info);
    }

    /**
     * 修改
     * @param Request $request
     * @return mixed
     * @throws \Illuminate\Validation\ValidationException
     */
    public function store(Request $request) {
        $this->validate($request, [
            'film_grading' => 'required',
            'specs' => 'required',
            'photo_content' => 'required',
            'photo_grade' => 'required'
            ]);
        $input = $request->input();


        $model = Config::where('key', 'film_grading' )->first();
        $model->value = $input['film_grading'];
        $model->save();

        $model = Config::where('key', 'specs' )->first();
        $model->value = $input['specs'];
        $model->save();

        $model = Config::where('key', 'photo_content' )->first();
        $model->value = $input['photo_content'];
        $model->save();

        $model = Config::where('key', 'photo_grade' )->first();
        $model->value = $input['photo_grade'];
        $model->save();

        return $this->success([]);
    }

}

